package com.distributedDataBase.action;

import com.distributedDataBase.pojo.Result;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpSession;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("ses")
public class SessionAction {

    @GetMapping("{username}")
    public Result add(@PathVariable("username") String username, HttpServletRequest request){
        HttpSession session = request.getSession();
        session.setAttribute("username",username);

        return new Result("200","session-add", username);
    }

    @GetMapping("get")
    public Result get(HttpServletRequest request){
        HttpSession session = request.getSession();
        String username = (String) session.getAttribute("username");
        return new Result("200","session-get",username);

    }
}
